﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using DreamBuilder.Common;
using DreamBuilder.Core.Container;
using DreamBuilder.Core.DAO;

namespace Web.Views.SystemLogin
{
    /// <summary>
    /// LoadMenuService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
     [System.Web.Script.Services.ScriptService]
    public class LoadMenuService : System.Web.Services.WebService
    {
        
        /// <summary>
        /// 获取菜单数据
        /// </summary>
        /// <returns></returns>
        [WebMethod]
        public void GetMenuData()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("menuId"));
            dt.Columns.Add(new DataColumn("menuText"));
            dt.Columns.Add(new DataColumn("menuUrl"));
            dt.Columns.Add(new DataColumn("menuImage"));
            dt.Columns.Add(new DataColumn("menuIndex"));

            dt.NewRow();
            dt.Rows.Add(Guid.NewGuid().ToString(),"地址信息", "http://localhost/iisstart.htm", "Images/Portal/Menu/address.png", "1");
            dt.NewRow();
            dt.Rows.Add(Guid.NewGuid().ToString(), "支持信息", "http://localhost/iisstart.htm", "Images/Portal/Menu/approval.png", "2");
            dt.NewRow();
            dt.Rows.Add(Guid.NewGuid().ToString(), "发文收文", "http://localhost/iisstart.htm", "Images/Portal/Menu/book.png", "3");
            dt.NewRow();
            dt.Rows.Add(Guid.NewGuid().ToString(), "日历信息", "http://localhost/iisstart.htm", "Images/Portal/Menu/calendar.png", "4");
            dt.NewRow();
            dt.Rows.Add(Guid.NewGuid().ToString(),"地址", "http://localhost/iisstart.htm", "Images/Portal/Menu/address.png", "5");
            dt.NewRow();
            dt.Rows.Add(Guid.NewGuid().ToString(),"默认", "http://localhost/iisstart.htm", "Images/Portal/Menu/default.png", "6");
            dt.NewRow();
            dt.Rows.Add(Guid.NewGuid().ToString(),"邮件", "http://localhost/iisstart.htm", "Images/Portal/Menu/email.png", "7");
            dt.NewRow();
            dt.Rows.Add(Guid.NewGuid().ToString(),"游戏", "http://localhost/iisstart.htm", "Images/Portal/Menu/game.png", "8");
            dt.NewRow();
            dt.Rows.Add(Guid.NewGuid().ToString(),"招聘信息", "http://localhost/iisstart.htm", "Images/Portal/Menu/hr.png", "9");
            dt.NewRow();
            dt.Rows.Add(Guid.NewGuid().ToString(),"新闻", "http://localhost/iisstart.htm", "Images/Portal/Menu/news.png", "10");
            dt.NewRow();
            dt.Rows.Add(Guid.NewGuid().ToString(),"通知通告", "http://localhost/iisstart.htm", "Images/Portal/Menu/notice.png", "11");
            dt.NewRow();
            dt.Rows.Add(Guid.NewGuid().ToString(),"时政新闻", "http://localhost/iisstart.htm", "Images/Portal/Menu/overtime.png", "12");
           dt.AcceptChanges();

           string sJson =   DataTableToJson.ToJson(dt);

            this.Context.Response.Write(sJson);

        }

        /// <summary>
        /// 获取导航菜单数据
        /// <param name="parent_Id">父节点ID（顶级菜单的该项为null）</param>
        /// </summary>
        [WebMethod]
        public void GetNavigateMenuData(string parent_Id)
        {
            IMDataHelper dal = new IMDataHelper();
            string sql = "";
            if (string.IsNullOrEmpty(parent_Id))
            {
                sql = "  SELECT a.Menu_ID as menuId,a.Parent_Menu_ID as parentMenuId,a.Menu_URL as menuUrl,a.Order_Num as menuOrder,b.vDesc as menuText,b.vCulture FROM P_Auth_Menu as a join (select * from Config_Res_System where vStringKey in (SELECT Menu_ID FROM P_Auth_Menu)) as b on a.MENU_ID =b.vStringKey where b.vPageUrl = 'Public/Modules' and vCulture='zh-cn' and Parent_Menu_Id is null";
            }
            else
            {
                sql = "  SELECT a.Menu_ID as menuId,a.Parent_Menu_ID as parentMenuId,a.Menu_URL as menuUrl,a.Order_Num as menuOrder,b.vDesc as menuText,b.vCulture FROM P_Auth_Menu as a join (select * from Config_Res_System where vStringKey in (SELECT Menu_ID FROM P_Auth_Menu)) as b on a.MENU_ID =b.vStringKey where b.vPageUrl = 'Public/Modules' and vCulture='zh-cn' and Parent_Menu_Id ='" + parent_Id + "'";
            }
            sql = sql + " order by Order_Num asc";

            DataTable dt = dal.DBHelper.ExecuteDataSet(sql).Tables[0];
            string sJson ="";
            if (dt.Rows.Count > 0)
            {
               sJson = DataTableToJson.ToJson(dt);
            }
            else
            {
                sJson = "Empty";
            }
            this.Context.Response.Write(sJson);
        }


        public string GetPublicString(string resBaseName, string name)
        {
            return CResManager.GetPublicString(resBaseName, name);
        }
    }
}
